package com.hong.arithmetic.cas;

import java.util.concurrent.atomic.AtomicReference;

/**
 * @author: csh
 * @Date: 2022/8/6 21:05
 * @Description: cas工具类 通过jdk自带AtomicReference 实现
 */
public class CasV2 {

    public CasV2() {
    }

    public CasV2(AtomicReference<Integer> value) {
        this.value = value;
    }

    //内存的值
    AtomicReference<Integer> value;

    //获取值
    public Integer getValue() {
        return value.get();
    }

    //对比值
    public boolean compareAndSet(int defaultValue, int newValue) {
        return value.compareAndSet(defaultValue, newValue);
    }


}
